<?php
/* @var $this DefaultController */

$this->breadcrumbs=array(
	$this->module->id,
);

$urlArray = array('/marcar/entrenar/getphoto', 'format'=>'png');
$url = CHtml::normalizeUrl($urlArray);
$idUrl = CHtml::normalizeUrl(array_merge($urlArray, array('id'=>'user_id')));

$boton = CHtml::button('Enviar foto', array('onclick'=>'take_snapshot();'));
$listaUsuarios = Interfaz::ldUsuarios();
?>

<div id="mensaje"></div>

<h1>Entrenar Reconocimiento Facial</h1>

<div id="my_camera" style="width:320px; height:240px; margin: 40px auto;"></div>

<!-- Configure a few settings and attach camera -->
<script language="JavaScript">
	Webcam.set({
		image_format: 'png',
		jpeg_quality: 90
	});
	Webcam.attach( '#my_camera' );
	var url = <?php echo CJSON::encode($url);?>;
	var answerTimeout;
</script>

<center>
	<div><?php echo $listaUsuarios; ?></div>
	<div id="boton"><?php echo $boton; ?></div>
</center>

<script language="JavaScript">
	function take_snapshot() {
		// take snapshot and get image data
		var data_uri = Webcam.snap();
		var id = $('#profesor').val();
		var idUrl = <?php echo CJSON::encode($idUrl); ?>;
		idUrl = idUrl.replace('user_id', id);
		Webcam.upload(data_uri, idUrl, get_answer);
	}
	function set_answer (message) {
		var msg = $('#mensaje');
		clearTimeout(answerTimeout);
		msg.hide();
		msg.html(message);
		msg.fadeIn();
		answerTimeout = setTimeout(function() {msg.fadeOut();}, 3000);
	}
	function get_answer(code,text) {
		set_answer(text);
	}
</script>